﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Kokomo.Environment.Hosting
{
	public class FileDropBehavior : DropBehavior
	{
		public FileDropBehavior(EditorApplication application)
		{
			if (application == null) throw new ArgumentNullException("application");
			this.Application = application;
		}

		public EditorApplication Application { get; private set; }

		protected override void OnDragOver(System.Windows.FrameworkElement element, System.Windows.DragEventArgs e)
		{
			if (e.Data.GetDataPresent(DataFormats.FileDrop))
				e.Effects = DragDropEffects.Copy;
			else
				e.Effects = DragDropEffects.None;
		}

		protected override void OnDrop(System.Windows.FrameworkElement element, System.Windows.DragEventArgs e)
		{
			string[] fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
			if (fileNames != null)
			{
				foreach (var fileName in fileNames)
				{
					this.Application.OpenDocumentFromFile(fileName);
				}
			}
		}
	}
}
